package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.ProductService;
import com.atguigu.spzx.model.dto.product.ProductDto;
import com.atguigu.spzx.model.entity.base.ProductUnit;
import com.atguigu.spzx.model.entity.product.Product;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "商品模块")
@RestController
@RequestMapping(value="/admin/product/")
public class ProductController {

    @Autowired
    ProductService productService;

    @Operation(summary = "查询所有的计量单位")
    @GetMapping("findAllProductUnit")
    public Result findAllProductUnit(){

        List<ProductUnit> list = productService.findAllProductUnit();
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }


    @Operation(summary = "修改与审批商品模块的回显")
    @GetMapping("getByProductId/{ProductId}")
    public Result getByProductId(@PathVariable Long ProductId){
        Product product = productService.getProductById(ProductId);
        return Result.build(product, ResultCodeEnum.SUCCESS);

    }

    @Operation(summary = "添加商品")
    @PostMapping("addProduct")
    public Result addProduct(@RequestBody Product product){
        productService.addProduct(product);
        return Result.build(null, ResultCodeEnum.SUCCESS);

    }

    @Operation(summary = "删除商品")
    @DeleteMapping("deleteById/{id}")
    public Result deletedById(@PathVariable Long id){
        productService.deletedById(id);
        return Result.build(null, ResultCodeEnum.SUCCESS);

    }

    @Operation(summary = "修改审批状态")
    @GetMapping("updateAuditStatus/{productId}/{auditStatus}")
    public Result updateAuditStatus(@PathVariable Long productId,@PathVariable Integer auditStatus ){
        productService.updateAuditStatus(productId,auditStatus);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }


    @Operation(summary = "分页并查询所有商品列表")
    @GetMapping("{pageNum}/{pageSize}")
    public Result findByPage(@PathVariable Integer pageNum,@PathVariable Integer pageSize, ProductDto productDto){
        PageInfo pageInfo = productService.findByPage(pageNum,pageSize,productDto);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "修改商品上下架状态")
    @GetMapping("updateStatus/{productId}/{status}")
    public Result updateStatus(@PathVariable Long productId,@PathVariable Integer status ){
        productService.updateStatus(productId,status);
        return Result.build(null, ResultCodeEnum.SUCCESS);

    }

    @Operation(summary = "修改商品中sku的上下架状态")
    @GetMapping("updateSkuStatus/{skuId}/{status}")
    public Result updateSkuStatus(@PathVariable Long skuId,@PathVariable Integer status){
        productService.updateSkuId(skuId,status);
        return Result.build(null, ResultCodeEnum.SUCCESS);

    }

    @Operation(summary = "对商品进行修改操作")
    @PostMapping("updateProduct")
    public Result updateProduct(@RequestBody Product product){
        productService.updateProduct(product);
        return Result.build(null, ResultCodeEnum.SUCCESS);

    }

}
